使用delphi7开发的拍照、录像功能//开启摄像头
procedure TForm1.Button1Click(Sender: TObject);
var
index: integer;
begin
index := Combobox1.Items.IndexOf(Combobox1.Text);
hWndC := capCreateCaptureWindowA('My Own Capture Window',WS_CHILD or WS_VISIBLE ,
Panel1.Left,Panel1.Top,Panel1.Width,Panel1.Height,self.Handle,index);
//hWndC := capCreateCaptureWindowA('My Own Capture Window',WS_CHILD or WS_VISIBLE ,
// Panel1.Left,Panel1.Top,Panel1.Width,Panel1.Height,self.Handle,0);
if hWndC <> 0 then
begin
SendMessage(hWndC, WM_CAP_SET_CALLBACK_VIDEOSTREAM, 0, 0);
SendMessage(hWndC, WM_CAP_SET_CALLBACK_ERROR, 0, 0);
SendMessage(hWndC, WM_CAP_SET_CALLBACK_STATUSA, 0, 0);
SendMessage(hWndC, WM_CAP_DRIVER_CONNECT, 0, 0);
SendMessage(hWndC, WM_CAP_SET_SCALE, 1, 0);
SendMessage(hWndC, WM_CAP_SET_PREVIEWRATE, 66, 0);
SendMessage(hWndC, WM_CAP_SET_OVERLAY, 1, 0);
SendMessage(hWndC, WM_CAP_SET_PREVIEW, 1, 0);
end;
end;
//拍照保存图片
procedure TForm1.Button3Click(Sender: TObject);
var fileName: string;
begin
if not DirectoryExists('C:\\imgTemp') then //判断目录是否存在
try
begin
ForceDirectories('C:\\imgTemp'); // 创建目录
end;
finally
raise Exception.Create('创建目录失败!');
end;
fileName := 'C:\\imgTemp\\test.jpg';
if hWndC <> 0 then begin
if FileExists(pchar(fileName)) then
begin
DeleteFile(pchar(fileName));
end;
SendMessage(hWndC,WM_CAP_SAVEDIB,0,Longint(pchar(fileName)));
ShowMessage('保存图片成功!');
end
else begin
ShowMessage('请先开启摄像头!');
end;
end;
评论